		.text

		.global __context_init
__context_init:
		movl 	$0, %ebp
		ret
		
		.global __context_switch

__context_switch:
		movl	%ss:4(%esp),  %eax   // from_esp_ptr
		movl    %ss:8(%esp),  %ebx
		movl    %ss:12(%esp), %ecx   // to_esp
		movl    %ss:16(%esp), %edx

#ifdef CONTEXT_SWITCH_SAVEALL
		pusha
#else
		push %ebp
#endif
		pushf
	
		movl	%esp, 0(%eax)
		movl    $__context_switch_ret, 0(%ebx)
		movl    %ecx, %esp
		jmp     *%edx

__context_switch_ret:
		popf
#ifdef CONTEXT_SWITCH_SAVEALL
		popa
#else
		pop %ebp
#endif
		ret
		
